﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.BLL;
using BDCS.Model;

namespace BDCS.UI
{
    public partial class AddSubBuildTypes : Form
    {
        #region 成员字段
        private BDCS.BLL.T_SubBuildTyppes bllSubBuildTypes;
        private BDCS.Model.T_SubBuildTyppes modelSubBuildTypes;
        private DataSet dataSet;
        BDCS.BLL.T_BuildTyppes buildTypes;
        #endregion

        #region 构造函数
        public AddSubBuildTypes()
        {
            InitializeComponent();
        }
        #endregion

        #region 成员事件
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtSubBuildTypes.Text.Trim()))
            {
                bllSubBuildTypes = new BLL.T_SubBuildTyppes();
                modelSubBuildTypes = new Model.T_SubBuildTyppes();
                modelSubBuildTypes.BTID = Convert.ToInt32(this.cobBuildTypes.SelectedValue);
                modelSubBuildTypes.SBTName = this.txtSubBuildTypes.Text.Trim();
                modelSubBuildTypes.SBTypeDescribe = this.txtBuildTypeDescribe.Text.Trim();
                dataSet = new System.Data.DataSet();
                dataSet = bllSubBuildTypes.GetList("SBTName=" + "'" + this.txtSubBuildTypes.Text.Trim() + "'");
                if (dataSet.Tables[0].Rows.Count == 0)
                {
                    if (bllSubBuildTypes.Add(modelSubBuildTypes) != 0)
                    {
                        BDCS.Common.TreeViewState.IsChangedAttribute = true;
                        MessageBox.Show("子类建筑类别添加成功！");
                    }
                    else
                    {
                        MessageBox.Show("子类建筑类别添加失败，请重新添加！");
                    }
                }
                else
                {
                    MessageBox.Show("该子类建筑类别名称已经存在，请输入其他名称！");
                }
            }
            else
            {
                MessageBox.Show("请输入子类建筑类别名称！");
            }

        }

        private void AddSubBuildTypes_Load(object sender, EventArgs e)
        {
            CommboxDataBinding();
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtSubBuildTypes.Text = string.Empty;
            this.txtSubBuildTypes.Text = string.Empty;
        }
        #endregion
        #region 成员方法
        private void CommboxDataBinding()
        {
            buildTypes = new BLL.T_BuildTyppes();
            dataSet = new System.Data.DataSet();
            dataSet = buildTypes.GetAllList();
            this.cobBuildTypes.DataSource = dataSet.Tables[0];
            this.cobBuildTypes.DisplayMember = "BTName";
            this.cobBuildTypes.ValueMember = "BTID";
        }
        #endregion
    }
}
